home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS09.ADF
/
MicroEMACS
/
termio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-05-22
|
5KB
|
210 lines
/*
* The functions in this file negotiate with the operating system for
* characters, and write characters in a barely buffered fashion on the display.
* All operating systems.
*/
#include <exec/types.h>
#include <exec/exec.h>
#include <intuition/intuition.h>
#include <devices/console.h>
#include <stdio.h>
#include "keymap.h"
/*** CLOSE FLAGS FOR VARIOUS THINGS ***/
long mask = 0;
#define INTUITION 0x00000001
#define CONSOLE 0x00000002
#define SCREEN 0x00000004
#define WINDOW 0x00000008
#define MENU 0x00000020
struct IntuitionBase *IntuitionBase;
#define INTUITION_REV 29
static struct NewWindow NewWindow = {
0, 0,
640, 200,
-1, -1,
0,
SMART_REFRESH | ACTIVATE | WINDOWDRAG | WINDOWDEPTH | WINDOWSIZING,
NULL,
NULL,
"MEMACS 1.1",
NULL,
NULL,
100, 35,
640, 200,
WBENCHSCREEN
};
struct Window *Window;
static struct IOStdReq consoleIO;
static struct MsgPort consoleMsgPort;
#define NOBUF 1024
static char obuf[NOBUF];
static int nobuf;
/*
* This function fills in the keymap string fields
*/
static void FillIn(keytypes, keymap, n, strings)
UBYTE *keytypes;
UBYTE **keymap;
int n;
char **strings;
{
int i;
for (i = 0; i < n; ++i)
{
if (keytypes[i] & KCF_STRING)
{
if (*strings == NULL)
{ printf("too few KeyStrings\n"); exit(1); }
keymap[i] = *strings;
++strings;
}
}
if (*strings != NULL)
{ printf("too many KeyStrings\n"); exit(1); }
}
/*
* This function is called once to set up the terminal device streams.
* On VMS, it translates SYS$INPUT until it finds the terminal, then assigns
* a channel to it and sets it raw. On CPM it is a no-op.
*/
ttopen()
{
struct Task *task;
int i;
IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",
INTUITION_REV);
if (IntuitionBase == NULL) {
(VOID) printf("no intuition here!!\n");
close_things();
exit(2);
}
mask |= INTUITION;
Window = (struct Window *)OpenWindow(&NewWindow);
if (Window == NULL) {
(VOID) printf("could not open the window\n");
close_things();
exit(3);
}
mask |= WINDOW;
consoleIO.io_Data = (APTR) Window;
consoleIO.io_Length = sizeof(*Window);
if (OpenDevice("console.device", 0, &consoleIO, 0) != 0) {
(VOID) printf("could not open the console\n");
close_things();
exit(3);
}
mask |= CONSOLE;
consoleMsgPort.mp_Node.ln_Type = NT_MSGPORT;
consoleMsgPort.mp_Flags = 0;
if ((i = AllocSignal(-1)) == -1) {
(VOID) printf("could not alloc sig\n");
close_things();
exit(3);
}
task = (struct Task *)FindTask(NULL);
consoleMsgPort.mp_SigBit = i;
consoleMsgPort.mp_SigTask = task;
consoleIO.io_Message.mn_ReplyPort = &consoleMsgPort;
FillIn(HiKeyMapTypes, HiKeyMap, 40, HiStrings);
consoleIO.io_Command = CD_SETKEYMAP;
consoleIO.io_Data = (APTR) &KeyMap;
consoleIO.io_Length = sizeof(KeyMap);
DoIO(&consoleIO);
mouse_setup_menu();
mask |= MENU;
SetTaskPri( task, 1); /* raise priority a little as we are interactive */
mouse_enable();
nobuf = 0;
}
/*
* This function gets called just before we go back home to the command
* interpreter. On VMS it puts the terminal back in a reasonable state.
* Another no-operation on CPM.
*/
ttclose()
{
ttflush();
close_things();
}
/*
* Write a char or string to the display. On VMS, output is buffered, and
* we just put the characters in the big array, after checking for overflow.
* On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on
* MS-DOS (use the very very raw console output routine).
*/
ttputs( s)
char *s;
{
while( *s) ttputc( *s++);
}
ttputc(c)
{
if (nobuf >= NOBUF)
ttflush();
obuf[nobuf++] = c;
}
/*
* Flush terminal buffer. Does real work where the terminal output is buffered
* up. A no-operation on systems where byte at a time terminal I/O is done.
*/
ttflush()
{
if (nobuf != 0)
{
register int i = nobuf;
/* The DoIO write to the console trashes D7, so we declare
an unnecessary register variable here to for it to be saved */
consoleIO.io_Command = CMD_WRITE;
consoleIO.io_Data = (APTR) obuf;
consoleIO.io_Length = i;
DoIO(&consoleIO);
nobuf = 0;
}
}
/*
* Read a character from the terminal, performing no editing and doing no echo
* at all. More complex in VMS that almost anyplace else, which figures. Very
* simple on CPM, because the system can do exactly what you want.
*/
ttgetc()
{
char ch;
consoleIO.io_Command = CMD_READ;
consoleIO.io_Data = (APTR) &ch;
consoleIO.io_Length = 1;
DoIO(&consoleIO);
return((int)ch);
}
static close_things()
{
if (mask & MENU) mouse_clear_menu();
if(mask & CONSOLE) CloseDevice(&consoleIO);
if (mask & WINDOW) (VOID) CloseWindow(Window);
if (mask & INTUITION) (VOID) CloseLibrary((VOID *)IntuitionBase);
}